home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-28 | 2.4 KB | 89 lines | [TEXT/KAHL] |
- // this file contains a routine to illustrate the use of copybits to generate thumbnail images
- //
-
- #include <QDOffscreen.h>
- #include <PictUtil.h>
-
- extern RGBColor kRGBBlack ;
- extern RGBColor kRGBWhite ;
- extern Point gStaggerPos ;
-
-
-
- #define SCALEFACTOR 15 // percent
-
- void ShrinkToBWPict( WindowPtr theWindow )
- {
- Rect theBounds ;
- GWorldPtr theOldWorld, theNewWorld ;
- OSErr theErr ;
- CGrafPtr savedPort ;
- GWorldPtr savedGWorld ;
- WindowPtr newWindow ;
- GDHandle oldDevice ;
-
- PictInfo thePictInfo ;
- PaletteHandle thePictPalette = nil ;
- CTabHandle thePictCTab = nil ;
-
- float scaleFactor = SCALEFACTOR / 100.0 ;
-
-
- // get the GWorld from the window refcon
- theOldWorld = (GWorldPtr)GetWRefCon ( theWindow );
-
- // get the bounds of the window
- theBounds = theOldWorld->portRect ;
-
- // apply the scaling factor
- theBounds.top = scaleFactor * theBounds.top ;
- theBounds.left = scaleFactor * theBounds.left ;
- theBounds.bottom = scaleFactor * theBounds.bottom ;
- theBounds.right = scaleFactor * theBounds.right ;
-
- // make a new one-bit gworld to hold the shrunken image
- theErr = NewGWorld( &theNewWorld, 1, &theBounds, nil, nil, 0L ) ;
-
- if( theErr != noErr )
- return ;
-
- // save the world
- GetGWorld( &savedPort, &oldDevice ) ;
- SetGWorld( theNewWorld, nil ) ;
-
-
- RGBForeColor( &kRGBBlack ) ; // ensure the fg and bg colors are
- RGBBackColor( &kRGBWhite ) ; // as anticipated
- EraseRect( &theBounds ) ; // clear the area for the pict
- PenMode( srcCopy ) ; // ensure the t/f mode is as expected
-
-
- // render the image into the offscreen buffer
- CopyBits( &((GrafPtr)theOldWorld)->portBits,
- &((GrafPtr)theNewWorld)->portBits,
- &theOldWorld->portRect,
- &theNewWorld->portRect,
- patCopy | ditherCopy,
- nil ) ;
-
- SetGWorld( savedPort, oldDevice ) ;
-
- // create the window
- OffsetRect( &theBounds, gStaggerPos.h, gStaggerPos.v) ;
- gStaggerPos.h += 16 ;
- gStaggerPos.v += 16 ; // heh - should roll these around, but you wont
- // create more than a couple of windows, will you :-)
-
- newWindow = NewCWindow( nil, &theBounds, "\pplayTime", true,
- documentProc, (WindowPtr)-1, true, (long)theNewWorld );
-
- // make sure it is visible
- ShowWindow( newWindow ) ;
-
- SetGWorld( (CGrafPtr)newWindow, nil ) ;
-
- // invalidate the content region of the window - we don't do any drawing to it here.
- InvalRect ( &theBounds );
-
- SetGWorld( savedPort, oldDevice ) ;
- }